define([ "dojox/charting/Chart",
         "dojox/charting/themes/Claro",
         "dojox/charting/plot2d/Lines",
         "dojox/charting/plot2d/StackedAreas",
         "dojo/store/JsonRest",
         "dojox/charting/StoreSeries",
         "dojox/charting/axis2d/Default",
         "dojo/dom",
         ],
		function(Chart, theme, LinesPlot, StackedAreasPlot, JsonRestStore, StoreSeries) {

			// Store the original text before changing it
			var originalText = "";
			var node;
			var store = new JsonRestStore({target:"/vboxfarm/api/hosts/values/"});

			// x and y coordinates used for easy understanding of where they should display
			// Data represents website visits over a week period
			var chartData = [
				{ x: 2.9, y: 12378 },
				{ x: 3.2, y: 21882 },
				{ x: 5.5, y: 17654 },
				{ x: 6.8, y: 15833 },
				{ x: 9.1, y: 16122 }
			];

			// Return the module's return value
			return {
				updateText : function(id, message) {
					node = dom.byId(id);
					originalText = node.innerHTML;
					node.innerHTML = message;
				},
				restoreText : function(id) {
					node.innerHTML = originalText;
				},
				placeCpuChart : function(id) {
					// Create the chart within it's "holding" node
					var chart = new Chart(id, {title: "CPU Usage (%)"});

					var series = new StoreSeries(store, { query: ""+dojo.config.hostId+"/CPU-Load-User"}, {x:"x",y:"y"});
					chart.setTheme(theme);

					chart.addPlot("default", {
						type : LinesPlot,
						fontColor : "black",
					});
					
					chart.addAxis("x", {});
					chart.addAxis("y", {vertical: true,
						min: 0});

					chart.addSeries("CPU", series);

					chart.render();
				},
				
				placeMemChart : function(id) {
					var chart = new Chart(id, {title: "Memory Free vs Used (kB)"});
					chart.setTheme(theme);
					chart.addPlot("default", {
						type : StackedAreasPlot,
						fontColor : "black",
					});

					chart.addAxis("x", {});
					chart.addAxis("y", {vertical: true,
						min: 0, offset: -30});
					chart.addSeries("Free", new StoreSeries(store, { query: ""+dojo.config.hostId+"/RAM-Usage-Free"}, 
							"y"),
							{stroke: {color: "green", width:3}, fill: "green"});
					chart.addSeries("Used", new StoreSeries(store, { query: ""+dojo.config.hostId+"/RAM-Usage-Used"}, 
							"y"),
							{stroke: {color: "red", width:3}, fill:"pink"});
					chart.render();
				}
			};
		});